//
//  LatexShadowView.m
//  latex_demo
//
//  Created by heaton on 2020/7/31.
//

#import "LatexShadowView.h"
#import <React/RCTUIManager.h>
#import "CusMathLabel.h"
@implementation LatexShadowView{
  __weak RCTBridge *_bridge;
  NSString *_mathStr;
}

- (instancetype)initWithBridge:(RCTBridge *)bridge
{
  self = [super init];
  if (self) {
    _bridge = bridge;
  }
  return self;
}

- (void)setLatex:(NSString *)mathStr{
  NSLog(@"shadowview setLatex ---- %@",mathStr);
  _mathStr = mathStr;
  CusMathLabel *mathView = [[CusMathLabel alloc] init];
  mathView.fontSize = 16.0;
  mathView.labelMode = kMTMathUILabelModeText;
  mathView.latex = mathStr;
  CGSize size = [mathView sizeThatFits:CGSizeMake(MAXFLOAT, MAXFLOAT)];
  
  self.intrinsicContentSize = size;
}

- (void)uiManagerWillPerformMounting{
  NSLog(@"uiManagerWillPerformMounting");
  [_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
    CusMathLabel *mathView = (CusMathLabel *)viewRegistry[self.reactTag];
    if (!mathView) {
      return;
    }
    mathView.latex = _mathStr;
  }];
}


@end
